
<script setup>
  import { useRouter } from 'vue-router';

  defineProps(['mainTitle', 'itemList']);

  const router = useRouter();
  function onClick() {
    router.push('/')
  }
</script>

<template>
  <div class="goods">
    <div class="wapper">
      <!-- 顶部 -->
      <div class="goods-title">
        <h2>-{{ mainTitle }}-</h2>
        <span>温柔柔软，品质之选</span>
      </div>
      <div class="see" @click="onClick">查看全部<el-icon><ArrowRight /></el-icon></div>
      <div class="goods-wapper">
        <div class="goods-item"
        v-for="(item, i) in itemList"
        :key="i"
        >
        <img :src="item.picture" alt="">
        <h4>{{ item.name }}</h4>
        <span>{{ item.desc }}</span>
        <span class="price">￥{{ item.price }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scope>
  @import '@/assets/styles/main.scss';
  .goods {
    width: 100%;
    margin: 10px 0;
    background-color: #F5F5F5;
    margin-top: 20px;
    text-align: center;
    .wapper {
      position: relative;
      width: 1240px;
      margin: 0 auto;
      background-color: #fff;
      padding: 30px 50px;
      box-sizing: border-box;
    }
    .goods-title {
      h2 {
        margin: 5px 0;
        font-size: 28px;
        color: #666666;
        font-weight: 500;
      }
      span {
        display: block;
        margin-top: 20px;
        margin-bottom: 30px;
        color: #aaa;
      }
    }
    .goods-wapper {
      display: grid;
      grid-template-columns: repeat(5, 1fr);
      .goods-item {
        width: 220px;
        box-sizing: border-box;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 15px 30px;
        transition: all .5s;
        img {
          width: 160px;
          height: 160px;
          // 图片自适应
          object-fit: cover;
        }
        h4 {
          width: 160px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 16px;
          font-weight: normal;
          margin: 10px 0;
        }
        span {
          width: 160px;
          display: block;
          font-size: 14px;
          color: #aaa;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .price {
          font-size: 18px;
          margin-top: 10px;
          color: #cf4444;
        }
        &:hover {
          transform: translate3d(0,-3px,0);
          box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
        }
      }
    }
  }
</style>
